import Vue from 'vue'
import format from 'date-fns/format'
// 自定义过滤器
Vue.filter('date-format', function (value, formatStr = 'yyyy-MM-dd HH:mm:ss') {
    if (value == '' || value == undefined) {
        return '';
    }
    if (typeof (value) == 'string') {
        value = new Date(value)
    }
    return format(value, formatStr);
});

Vue.filter('time-range', function (value, formatStr = 'HH:mm') {
    if (value == '' || value == undefined) {
        return '';
    }
    if (value.indexOf('-') > 0) {
        let arrTime = value.split('-');
        let startTime = arrTime[0].trim();
        let endTime = arrTime[1].trim();
        startTime = startTime.substring(0, startTime.length - 3);
        endTime = endTime.substring(0, endTime.length - 3);
        return startTime + '~' + endTime;
    }
    return '';
});
